import mergeWith from 'lodash/mergeWith';
import isEmpty from 'lodash/isEmpty';

export const baseHost = process.env.VUE_APP_BASE_HOST;

export const baseURL = [baseHost, process.env.VUE_APP_RUNTIME_ENV, process.env.VUE_APP_PROJECT_NAME].join('/');
export const PLATFORM = process.env.VUE_APP_PLATFORM;

const accountInfo = {
  version: process.env.VUE_APP_VERSION,
  appName: process.env.VUE_APP_NAME
};

console.log(process.env);

export const VUE_APP_ENV = process.env.VUE_APP_ENV;

if (uni.getAccountInfoSync) {
  const info = uni.getAccountInfoSync();
  const envVersion = info?.miniProgram?.envVersion;
  mergeWith(
    accountInfo,
    {
      appId: info?.miniProgram?.appId,
      version: info?.miniProgram?.version,
      envVersion: ['develop', 'trial', 'release'].includes(envVersion) ? envVersion : 'develop',
      pluginAppId: info?.plugin?.appId,
      appName: info?.appName
    },
    (objValue, srcValue) => (!isEmpty(srcValue) ? srcValue : objValue)
  );
}

console.log(accountInfo);

export { accountInfo };

export default {
  baseHost,
  baseURL,
  accountInfo
};
